package com.yiji.fintech.musfinance.common.strategy.unique;

import com.acooly.core.utils.Collections3;
import com.yiji.fintech.musfinance.center.base.result.ResultFacade;
import com.yiji.fintech.musfinance.common.domain.base.BaseDomain;
import com.yiji.fintech.musfinance.common.exception.UniqueCheckException;
import com.yiji.fintech.musfinance.common.strategy.base.AbstractUniqueStrategy;
import com.yiji.fintech.musfinance.common.utils.TransStatusConverter;
import com.yiji.fintech.musfinance.entity.AbstractTransaction;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 通用唯一性校验
 * Created by ouwen@yiji.com} on 2017/9/27.
 */
@Service
public class CommonUniqueStrategy extends AbstractUniqueStrategy {
    @Override
    public void process(List<AbstractTransaction> datas, BaseDomain domain, ResultFacade result) {
        if(Collections3.isNotEmpty(datas)){
            AbstractTransaction transaction = datas.get(0);
            TransStatusConverter.converter(transaction.getTransStatus(),result);//交易结果转换
            throw new UniqueCheckException("订单唯一性校验不通过，内部流水【"+transaction.getBizOrderNo()+"】存在");
        }
    }
}
